/*
 * Created on 16 mai 2007
 */
package fr.mywiki.business.versioning.diff;

import java.util.List;

public class DiffTest {
	private static List computeDiff(Object[] a, Object[] b) {
		Diff diff = new Diff(a, b);
		List diffOut = diff.diff();
		return diffOut;
	}

	private static void computeAndwriteDiff(Object[] a, Object[] b) {
		System.out.println(toString(a) + ", " + toString(b) + " : "
				+ computeDiff(a, b));
	}

	public static void main(String[] args) {
		System.out.println("Hello world");
		Object[] a = new Object[] { "a", "b", "c", "d", "e" };

		Object[] b = new Object[] { "a", "x", "y", "b", "c", "j", "e", };

		computeAndwriteDiff(a, b); // add 1,2 ; del 3,3 ; add 5,5  
		computeAndwriteDiff(b, a); // del 1,2 ; del 5,5 ; add 3,3

		a = new Object[] { "a", "b", "c", "d", "e" };

		b = new Object[] { "a", "b", "c", "d", "e" };

		computeAndwriteDiff(a, b);
		computeAndwriteDiff(b, a);

		a = new Object[] { "a", "b", "c", "d", "e" };

		b = new Object[] { "a", "b", "c", "d", "e", "f" };

		computeAndwriteDiff(a, b);
		computeAndwriteDiff(b, a);
		
		a = new Object[] { "a", "b", "c", "d", "e" };

		b = new Object[] { "a", "b", "c", "d", "e", "f", "g" };

		computeAndwriteDiff(a, b);
		computeAndwriteDiff(b, a);

		a = new Object[] { "a", "b", "c", "d", "e" };

		b = new Object[] { "a", "b", "c", "j", "e" };

		computeAndwriteDiff(a, b);
		computeAndwriteDiff(b, a);

		a = new Object[] { "a", "b", "c", "d", "e" };

		b = new Object[] { "a", "x", "y", "b", "c", "d", "e", };

		computeAndwriteDiff(a, b);
		computeAndwriteDiff(b, a);

		a = new Object[] { "a", "b", "c", "d", "e" };

		b = new Object[] { "a", "b", "c", "d", };

		computeAndwriteDiff(a, b);
		computeAndwriteDiff(b, a);
		
		a = new Object[] { "a", "b", "c", "d", "e" };

		b = new Object[] { "a", "b", "f","g","c", "d", "e" };

		computeAndwriteDiff(a, b);
		computeAndwriteDiff(b, a);
	}

	private static String toString(Object[] a) {
		StringBuffer buf = new StringBuffer();
		for (int i = 0; i < a.length; i++)
			buf.append(a[i]);
		return buf.toString();
	}
}
